// $ANTLR : "sintactico.g" -> "Anasint.java"$

	package documentosRepositorio;
	
	import java.util.List;
	import java.util.ArrayList;
	import java.util.Iterator;

import antlr.TokenBuffer;
import antlr.TokenStreamException;
import antlr.TokenStreamIOException;
import antlr.ANTLRException;
import antlr.LLkParser;
import antlr.Token;
import antlr.TokenStream;
import antlr.RecognitionException;
import antlr.NoViableAltException;
import antlr.MismatchedTokenException;
import antlr.SemanticException;
import antlr.ParserSharedInputState;
import antlr.collections.impl.BitSet;

public class Anasint extends antlr.LLkParser       implements AnasintTokenTypes
 {
 
	
//	Lista que almacena los documentos del repositorio.
	private List<Documento> documentosRep = new ArrayList();

// 	Lista de palabras claves por las que se puede buscar el documento. 
	private List<String> palabrasClavesDoc;
	
	
	private void addDocumento(Documento documento){		
		this.documentosRep.add(documento);			
	}
	
	private void addPalabrasClaves(String palabraClave){
		this.palabrasClavesDoc.add(palabraClave);
	}
	
	public List<Documento> getDocumentosRep(){
		return this.documentosRep;
	}
	
	private String suprimeCorchetes(String texto){
		return texto.substring(1, texto.length()-1);
	}
	
	private String[] toArrayPalabrasClaves(){
			String[] palClaves = new String[this.palabrasClavesDoc.size()];	
			
			int i = 0;
			for(String palabra: this.palabrasClavesDoc){
				palClaves[i] = palabra;
				i++;
			}
			
			return palClaves;
	}
	
	public String toString(){
		String s = "";
		
		Iterator it = this.documentosRep.iterator();
		while(it.hasNext()){
			s += ((Documento)it.next()).toString();		
		}
		
		return s;
	}

protected Anasint(TokenBuffer tokenBuf, int k) {
  super(tokenBuf,k);
  tokenNames = _tokenNames;
}

public Anasint(TokenBuffer tokenBuf) {
  this(tokenBuf,1);
}

protected Anasint(TokenStream lexer, int k) {
  super(lexer,k);
  tokenNames = _tokenNames;
}

public Anasint(TokenStream lexer) {
  this(lexer,1);
}

public Anasint(ParserSharedInputState state) {
  super(state,1);
  tokenNames = _tokenNames;
}

	public final void repositorio() throws RecognitionException, TokenStreamException {
		
		
		try {      // for error handling
			{
			_loop3:
			do {
				if ((LA(1)==LITERAL_DOCUMENTO)) {
					documentos();
				}
				else {
					break _loop3;
				}
				
			} while (true);
			}
			match(Token.EOF_TYPE);
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_0);
		}
	}
	
	public final void documentos() throws RecognitionException, TokenStreamException {
		
		String comentario="", ruta="", fichero="", nombre="";
		
		try {      // for error handling
			match(LITERAL_DOCUMENTO);
			nombre=nombre();
			fichero=fichero();
			ruta=ruta();
			palabrasClaves();
			comentario=comentarios();
			
							
							Documento documento = new Documento(nombre, fichero, ruta,
							 comentario, this.toArrayPalabrasClaves());
							 
							 this.addDocumento(documento);
						
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_1);
		}
	}
	
	public final String  nombre() throws RecognitionException, TokenStreamException {
		String nombre = "";;
		
		Token  t = null;
		
		try {      // for error handling
			match(LITERAL_NOMBRE);
			t = LT(1);
			match(TEXTO);
			
				nombre = this.suprimeCorchetes(t.getText());
			
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_2);
		}
		return nombre;
	}
	
	public final String  fichero() throws RecognitionException, TokenStreamException {
		String fichero = "";;
		
		Token  t = null;
		
		try {      // for error handling
			match(LITERAL_FICHERO);
			t = LT(1);
			match(TEXTO);
			
				fichero = this.suprimeCorchetes(t.getText());
			
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_3);
		}
		return fichero;
	}
	
	public final String  ruta() throws RecognitionException, TokenStreamException {
		String ruta = "";;
		
		Token  t = null;
		
		try {      // for error handling
			match(LITERAL_RUTA);
			t = LT(1);
			match(TEXTO);
			
				ruta = this.suprimeCorchetes(t.getText());
			
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_4);
		}
		return ruta;
	}
	
	public final void palabrasClaves() throws RecognitionException, TokenStreamException {
		
		
		try {      // for error handling
			match(LITERAL_PALABRAS);
			match(LITERAL_CLAVES);
			match(11);
			listaPalabras();
			match(12);
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_5);
		}
	}
	
	public final String  comentarios() throws RecognitionException, TokenStreamException {
		String comentarios = "";
		
		Token  t = null;
		
		try {      // for error handling
			match(LITERAL_COMENTARIOS);
			t = LT(1);
			match(TEXTO);
			
					comentarios = this.suprimeCorchetes(t.getText());	
				
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_1);
		}
		return comentarios;
	}
	
	public final void listaPalabras() throws RecognitionException, TokenStreamException {
		
		Token  p = null;
		Token  p1 = null;
		
		try {      // for error handling
			p = LT(1);
			match(PALABRA);
			
								this.palabrasClavesDoc = new ArrayList();
								this.addPalabrasClaves(p.getText());
							
			{
			_loop11:
			do {
				if ((LA(1)==COMA)) {
					match(COMA);
					p1 = LT(1);
					match(PALABRA);
					
										this.addPalabrasClaves(p1.getText());
									
				}
				else {
					break _loop11;
				}
				
			} while (true);
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_6);
		}
	}
	
	
	public static final String[] _tokenNames = {
		"<0>",
		"EOF",
		"<2>",
		"NULL_TREE_LOOKAHEAD",
		"\"DOCUMENTO\"",
		"\"NOMBRE\"",
		"TEXTO",
		"\"FICHERO\"",
		"\"RUTA\"",
		"\"PALABRAS\"",
		"\"CLAVES\"",
		"\"{\"",
		"\"}\"",
		"PALABRA",
		"COMA",
		"\"COMENTARIOS\""
	};
	
	private static final long[] mk_tokenSet_0() {
		long[] data = { 2L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
	private static final long[] mk_tokenSet_1() {
		long[] data = { 18L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
	private static final long[] mk_tokenSet_2() {
		long[] data = { 128L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2());
	private static final long[] mk_tokenSet_3() {
		long[] data = { 256L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_3 = new BitSet(mk_tokenSet_3());
	private static final long[] mk_tokenSet_4() {
		long[] data = { 512L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_4 = new BitSet(mk_tokenSet_4());
	private static final long[] mk_tokenSet_5() {
		long[] data = { 32768L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_5 = new BitSet(mk_tokenSet_5());
	private static final long[] mk_tokenSet_6() {
		long[] data = { 4096L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_6 = new BitSet(mk_tokenSet_6());
	
	}
